package string;

public class CharAtDemo {
    public static void main(String[] args) {
        //            01234567890
        String str = "www.tedu.cn";
        char c = str.charAt(4);
        System.out.println(c);

        for (int i = 0; i < str.length(); i++) {
            c = str.charAt(i);
            System.out.println(c);
        }

        //验证回文
        String line = "上海自来水自来海上";
/*        //上
        char c1 = line.charAt(0);
        char c2 = line.charAt(line.length()-1-0);
        //海
        c1 = line.charAt(1);
        c2 = line.charAt(line.length()-1-1);
        //自
        c1 = line.charAt(2);
        c2 = line.charAt(line.length()-1-2);
        //来
        c1 = line.charAt(3);
        c2 = line.charAt(line.length()-1-3);*/

        //变成循环   i:0,1,2,3
        /*boolean check = true;
        for(int i=0;i<line.length()/2;i++){
            char c1 = line.charAt(i);
            char c2 = line.charAt(line.length()-1-i);
            if(c1!=c2){
                System.out.println("不是回文");
                check = false;
                break;
            }
        }
        if(check) {
            System.out.println("是回文");
        }*/


       /* for(int i=0;i<line.length()/2;i++){
            char c1 = line.charAt(i);
            char c2 = line.charAt(line.length()-1-i);
            if(c1!=c2){
                System.out.println("不是回文");
                return;
            }
        }
        System.out.println("是回文");*/


        for (int i = 0; i < line.length() / 2; i++) {
            char c1 = line.charAt(i);
            char c2 = line.charAt(line.length() - 1 - i);
            if (c1 != c2) {
                System.out.print("不");
                break;
            }
        }
        System.out.println("是回文");
    }
}
